Learn R Programming

spectrolab (version 0.0.18)

[.spectra: Subset spectra

Description

`[` Subsets spectra by sample names (rows) or (and) bands (columns)

Usage

# S3 method for spectra
[(x, i, j, simplify = TRUE)

Value

usually a spectra object, but see param `simplify`

Arguments

x

spectra object

i

Sample names (preferred), index, or a logical vector of length nrow(x)

j

band labels, as numeric or character or a logical vector of length ncol(x). Do not use indexes!

simplify

Boolean. If TRUE (default), single band selections are returned as a named vector of values

Author

Jose Eduardo Meireles

Details

Subset operations based on samples (first argument) will match sample names or indexes, in that order. The spectra constructor ensures that names are not numeric nor are coercible to numeric, such that x[1:2, ] will return the first and second samples in the `spectra` object. Subsetting based on bands (second argument) matches the band labels, not indices! That is, x[ , 600] will give you the value data for the 600nm band and not the 600th band. Boolean vectors of the appropriate length can be used to subset samples and bands.

Examples

Run this code
library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)
head(names(spec), n = 3)
# by name
spec1 = spec[ "species_7" , ]
spec1
# by band
spec2 = spec[ , 400:700 ]
spec2

Run the code above in your browser using DataLab